/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_PLUGIN_LOADER_H
#define __COMMON_PLUGIN_LOADER_H

#include <stdio.h>
#include <dlfcn.h>
#include "data.h"
#include "list.h"

typedef char *(*z_plugin_namer)(); //type z_plugin_namer: callback from plugin which returns name
typedef int (*z_plugin_sic)(char *, int *); //type z_plugin_sic: callback to get the signal code associated with a name
typedef z_data (*z_plugin_handler)(int, z_data); //type z_plugin_handler: callback to handle signals to plugins

//struct z_plugin: a plugin handle
typedef struct
{
	char *path; //memberof z_plugin: the path to the plugin
	void *so; //memberof z_plugin: the handle of the dynamically-loaded shared object
	z_plugin_namer namer; //memberof z_plugin: the name callback
	z_plugin_sic sic; //memberof z_plugin: the name-to-signal callback
	int nsigs; //memberof z_plugin: the number of signals
	z_plugin_handler handler; //memberof z_plugin: the plugin signal handler callback
} z_plugin;

z_plugin z_plugin_init(char *path); //methodof z_plugin: initializer
int z_plugin_release(z_plugin p); //methodof z_plugin: uninitializer
int z_plugin_load(z_plugin *p); //methodof z_plugin: actually load the shared object
//returnof z_plugin_load: int: 1 on failure, 0 otherwise
int z_plugin_unload(z_plugin *p); //methodof z_plugin: unload the shared object without erasing the info for it
char *z_plugin_name(z_plugin *p); //methodof z_plugin: get the name of the plugin
int z_plugin_max_sig(z_plugin *p); //methodof z_plugin: gets the maximum signal code
int z_plugin_sig(z_plugin *p, char *s); //methodof z_plugin: converts signal name to signal code
z_data z_plugin_call(z_plugin *p, int s, z_data d); //methodof z_plugin: call a signal 's' with data 'd'

/// This is mostly used internally. For more info on how to use plugins look at common/test_plugin_loader.cpp.

#endif